package com.ruoyi.vehicle.config;

import org.influxdb.InfluxDB;
import org.influxdb.InfluxDBFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class InfluxDB1Config {

    @Value("${influxdb.url}")
    private String url;

    @Value("${influxdb.username}")
    private String username;

    @Value("${influxdb.password}")
    private String password;

    @Value("${influxdb.database}")
    private String database;

    @Bean
    public InfluxDB influxDB() {
        // 创建连接
        InfluxDB influxDB = InfluxDBFactory.connect(url, username, password);

        // 设置默认数据库
        influxDB.setDatabase(database);

        // 开启批量写入（优化性能）
        influxDB.enableBatch(
                1000,  // 批量大小
                100,   // 刷新间隔（毫秒）
                TimeUnit.MILLISECONDS
        );

        return influxDB;
    }
}